package com.itheima.filedemo;

import java.io.File;
import java.util.ArrayList;
import java.util.HashMap;

public class FileDemo9 {
    public static void main(String[] args) {
        File file = new File("FileModule");
        HashMap<String, Integer> hm = new HashMap<>();
        getCount(hm, file);
        System.out.println(hm);
    }

    private static void getCount(HashMap<String, Integer> hm, File file) {
        File[] paths = file.listFiles();
        for (File path : paths) {
            if (path.isFile()) {
                String fileName = path.getName();
                int i = fileName.lastIndexOf(".");
                if (i > 0) {
                    String ext = fileName.substring(i + 1);
                    if (hm.containsKey(ext)) {
                        int count = hm.get(ext);
                        hm.put(ext, ++count);
                    } else {
                        hm.put(ext, 1);
                    }
                }
            } else {
                getCount(hm, path);
            }
        }
    }
}
